package com.fept.msgcore.msgserver.protocol.model.option;

import com.fept.msgcore.msgserver.protocol.model.base.ProtocolConstants;

/**
 * Created by Srma on 2/9/2017.
 */
public class EncryptOption  extends BaseOption {

    /**
     *
     */
    private static final long serialVersionUID = -7058807558783409798L;

    public static final int NONE = 0x00;
    public static final int DES = 0x01;
    public static final int DES3 = 0x02;
    public static final int AES = 0x03;

    private int algorithm;
    private int key;

    public EncryptOption() {
        this.setType(ProtocolConstants.OPTION_ENCRYPT);
    }

    /**
     *
     */
    @Override
    public byte[] pack() {
        byte[] optionBytes = new byte[1 + 1];
        optionBytes[0] = (byte) (this.algorithm & 0xFF);
        optionBytes[1] = (byte) (this.key & 0xFF);
        this.setValue(optionBytes);
        this.setLength(optionBytes.length);
        return super.pack();
    }

    /**
     *
     */
    @Override
    public void unpack(byte[] data, int offset) {
        super.unpack(data, offset);

        data = this.getValue();
        offset = 0;

        this.setAlgorithm(data[offset]);
        offset += 1;

        this.setKey(data[offset]);
        offset += 1;
    }

    /**
     * @return the algorithm
     */
    public int getAlgorithm() {
        return algorithm;
    }

    /**
     * @param algorithm
     *            the algorithm to set
     */
    public void setAlgorithm(int algorithm) {
        this.algorithm = algorithm;
    }

    /**
     * @return the key
     */
    public int getKey() {
        return key;
    }

    /**
     * @param key
     *            the key to set
     */
    public void setKey(int key) {
        this.key = key;
    }

}
